var linecode = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_ ";

function bincode(number,size) { number = (number).toString(2); while (number.length < size) number="0"+number; return number; }

function Export_Line_Encryption(string) {

var bitcode = "";
var output = "";
var temp = "";

string = string.replace(/_-/g, "__");

for (i=0; i<string.length ; i++) {

if ( i+1 == string.length ) string += "_";

if ((string.charAt(i) != "_")&&(string.charAt(i+1) != "_")) temp = Number(string.charAt(i))*10+Number(string.charAt(i+1));
if ((string.charAt(i) == "_")&&(string.charAt(i+1) == "_")) { temp = 120; } else {
if (string.charAt(i) == "_") temp = 100+Number(string.charAt(i+1));
if (string.charAt(i+1) == "_") temp = 110+Number(string.charAt(i));
}

bitcode += bincode(temp,7);

temp = bitcode.slice(0,6);

for (t=0; t<64; t++) if ( temp == bincode(t,6) ) output += linecode.charAt(t);

bitcode = bitcode.slice(6);

if ( i+2 == string.length ) while ( bitcode.length < 6 ) bitcode += "0";


if ( bitcode.length == 6 ) {
for (t=0; t<64; t++) if ( bitcode == bincode(t,6) ) output += linecode.charAt(t);
bitcode = "";
}

i++;

}

return output;

}





function numcode(binary) {

var output = 0, i = 1, decVal = 0, dec = 0;

while ( binary >= 1 ) {

decVal = binary % 2;

if ( decVal == 1 ) {
dec = i * 1;
output += dec;
i = i * 2;
binary /= 10;
binary = parseInt ( binary );

} else {

i = i * 2;
binary /= 10;
binary = parseInt( binary );
}

}

if ( output < 10 ) output = "0" + output;

return output;

}



function Export_Line_Decryption(string) {

var bitcode = "";
var output = "";
var temp = "";

for (i=0; i<string.length ; i++) {

for (t=0; t<64; t++) if ( string.charAt(i) == linecode.charAt(t) ) temp = t;
bitcode += bincode(temp,6);
if ( i+1 == string.length ) while ( bitcode.length < 6 ) bitcode += "0";

if ( bitcode.length > 6 ) {
temp = bitcode.slice(0,7);
if ( temp == bincode(120,7) ) output += "__";
else if ( temp == bincode(119,7) ) if ( i+1 == string.length ) { output += "9"; } else { output += "9_"; }
else if ( temp == bincode(118,7) ) if ( i+1 == string.length ) { output += "8"; } else { output += "8_"; }
else if ( temp == bincode(117,7) ) if ( i+1 == string.length ) { output += "7"; } else { output += "7_"; }
else if ( temp == bincode(116,7) ) if ( i+1 == string.length ) { output += "6"; } else { output += "6_"; }
else if ( temp == bincode(115,7) ) if ( i+1 == string.length ) { output += "5"; } else { output += "5_"; }
else if ( temp == bincode(114,7) ) if ( i+1 == string.length ) { output += "4"; } else { output += "4_"; }
else if ( temp == bincode(113,7) ) if ( i+1 == string.length ) { output += "3"; } else { output += "3_"; }
else if ( temp == bincode(112,7) ) if ( i+1 == string.length ) { output += "2"; } else { output += "2_"; }
else if ( temp == bincode(111,7) ) if ( i+1 == string.length ) { output += "1"; } else { output += "1_"; }
else if ( temp == bincode(110,7) ) if ( i+1 == string.length ) { output += "0"; } else { output += "0_"; }
else if ( temp == bincode(109,7) ) output += "_9";
else if ( temp == bincode(108,7) ) output += "_8";
else if ( temp == bincode(107,7) ) output += "_7";
else if ( temp == bincode(106,7) ) output += "_6";
else if ( temp == bincode(105,7) ) output += "_5";
else if ( temp == bincode(104,7) ) output += "_4";
else if ( temp == bincode(103,7) ) output += "_3";
else if ( temp == bincode(102,7) ) output += "_2";
else if ( temp == bincode(101,7) ) output += "_1";
else if ( temp == bincode(100,7) ) output += "_0";
else output += numcode(temp);
bitcode = bitcode.slice(7);
}

}

output = output.replace(/__/g, "_-");
return output;

}



function ABC_Decryption(string) {
var output = "";
for (i=0; i<string.length ; i++) {
output += linecode.charAt( Number(string.charAt(i))*10+Number(string.charAt(i+1)) );
i++;
}
return output;
}



function ABC_Encryption(string) {
var output = "";
for (i=0; i<string.length ; i++) {
for (t=0;  t<10; t++) if ( string.charAt(i) == linecode.charAt(t) ) output += "0"+t;
for (t=10; t<65; t++) if ( string.charAt(i) == linecode.charAt(t) ) output += t;
}
return output;
}
